        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>Simplex class / box2d Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="box2d" data-type="Simplex">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../box2d.html">box2d</a> &rsaquo; <a href="../box2d/Simplex.html">Simplex</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>Simplex</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<pre class="source">
class Simplex {
 final SimplexVertex v1;
 final SimplexVertex v2;
 final SimplexVertex v3;
 final List&lt;SimplexVertex&gt; vertices;
 int count;

 Simplex() :
   count = 0,
   v1 = new SimplexVertex(),
   v2 = new SimplexVertex(),
   v3 = new SimplexVertex(),
   vertices = new List&lt;SimplexVertex&gt;(3),
   e13 = new vec2.zero(),
   e12 = new vec2.zero(),
   e23 = new vec2.zero(),
   case2 = new vec2.zero(),
   case22 = new vec2.zero(),
   case3 = new vec2.zero(),
   case33 = new vec2.zero() {

   vertices[0] = v1;
   vertices[1] = v2;
   vertices[2] = v3;
 }

 /** Pooling. */
 final vec2 e13;
 final vec2 e23;
 final vec2 e12;
 final vec2 case2;
 final vec2 case22;
 final vec2 case3;
 final vec2 case33;

 void readCache(SimplexCache cache, DistanceProxy proxyA,
     Transform transformA, DistanceProxy proxyB,
     Transform transformB) {
   assert (cache.count &lt;= 3);

   // Copy data from cache.
   count = cache.count;

   for (int i = 0; i &lt; count; ++i) {
     SimplexVertex v = vertices[i];
     v.indexA = cache.indexA[i];
     v.indexB = cache.indexB[i];
     vec2 wALocal = proxyA.vertices[v.indexA];
     vec2 wBLocal = proxyB.vertices[v.indexB];
     Transform.mulToOut(transformA, wALocal, v.wA);
     Transform.mulToOut(transformB, wBLocal, v.wB);
     v.w.copyFrom(v.wB).sub(v.wA);
     v.a = 0.0;
   }

   // Compute the new simplex metric, if it is substantially different than
   // old metric then flush the simplex.
   if (count &gt; 1) {
     num metric1 = cache.metric;
     num metric2 = getMetric();
     if (metric2 &lt; 0.5 * metric1 || 2.0 * metric1 &lt; metric2 || metric2 &lt;
         Settings.EPSILON) {
       // Reset the simplex.
       count = 0;
     }
   }

   // If the cache is empty or invalid ...
   if (count == 0) {
     SimplexVertex v = vertices[0];
     v.indexA = 0;
     v.indexB = 0;
     vec2 wALocal = proxyA.vertices[0];
     vec2 wBLocal = proxyB.vertices[0];
     Transform.mulToOut(transformA, wALocal, v.wA);
     Transform.mulToOut(transformB, wBLocal, v.wB);
     v.w.copyFrom(v.wB).sub(v.wA);
     count = 1;
   }
 }

 void writeCache(SimplexCache cache) {
   cache.metric = getMetric();
   cache.count = count;

   for (int i = 0; i &lt; count; ++i) {
     cache.indexA[i] = (vertices[i].indexA);
     cache.indexB[i] = (vertices[i].indexB);
   }
 }

 void getSearchDirection(vec2 out) {
   switch (count) {
     case 1 :
       out.copyFrom(v1.w).negate();
       return;
     case 2 :
       e12.copyFrom(v2.w).sub(v1.w);
       // use out for a temp variable real quick
       out.copyFrom(v1.w).negate();
       num sgn = cross(e12, out);

       if (sgn &gt; 0) {
         // Origin is left of e12.
         out = cross(1, e12);
       }
       else {
         // Origin is right of e12.
         out = cross(e12, 1);
       }
       break;
     default :
       assert (false);
       out.splat(0.0);
       return;
   }
 }


 /**
  * this returns pooled objects. don't keep or modify them
  */
 void getClosestPoint(vec2 out) {
   switch (count) {
     case 0 :
       assert (false);
       out.splat(0.0);
       return;
     case 1 :
       out.copyFrom(v1.w);
       return;
     case 2 :
       case22.copyFrom(v2.w).scale(v2.a);
       case2.copyFrom(v1.w).scale(v1.a).add(case22);
       out.copyFrom(case2);
       return;
     case 3 :
       out.splat(0.0);
       return;
     default :
       assert (false);
       out.splat(0.0);
       return;
   }
 }


 void getWitnessPoints(vec2 pA, vec2 pB) {
   switch (count) {
     case 0 :
       assert (false);
       break;

     case 1 :
       pA.copyFrom(v1.wA);
       pB.copyFrom(v1.wB);
       break;

     case 2 :
       case2.copyFrom(v1.wA).scale(v1.a);
       pA.copyFrom(v2.wA).scale(v2.a).add(case2);
       case2.copyFrom(v1.wB).scale(v1.a);
       pB.copyFrom(v2.wB).scale(v2.a).add(case2);

       break;

     case 3 :
       pA.copyFrom(v1.wA).scale(v1.a);
       case3.copyFrom(v2.wA).scale(v2.a);
       case33.copyFrom(v3.wA).scale(v3.a);
       pA.add(case3).add(case33);
       pB.copyFrom(pA);
       break;

     default :
       assert (false);
       break;
   }
 }

 num getMetric() {
   switch (count) {
     case 0 :
       assert (false);
       return 0.0;

     case 1 :
       return 0.0;

     case 2 :
       return distance(v1.w, v2.w);

     case 3 :
       case3.copyFrom(v2.w).sub(v1.w);
       case33.copyFrom(v3.w).sub(v1.w);
       return cross(case3, case33);

     default :
       assert (false);
       return 0.0;
   }
 }

 /**
  * Solve a line segment using barycentric coordinates.
  */
 void solve2() {
   vec2 w1 = v1.w;
   vec2 w2 = v2.w;
   e12.copyFrom(w2).sub(w1);

   // w1 region
   num d12_2 = -dot(w1, e12);
   if (d12_2 &lt;= 0.0) {
     // a2 &lt;= 0, so we clamp it to 0
     v1.a = 1.0;
     count = 1;
     return;
   }

   // w2 region
   num d12_1 = dot(w2, e12);
   if (d12_1 &lt;= 0.0) {
     // a1 &lt;= 0, so we clamp it to 0
     v2.a = 1.0;
     count = 1;
     v1.setFrom(v2);
     return;
   }

   // Must be in e12 region.
   num inv_d12 = 1.0 / (d12_1 + d12_2);
   v1.a = d12_1 * inv_d12;
   v2.a = d12_2 * inv_d12;
   count = 2;
 }

 /**
  * Solve a line segment using barycentric coordinates.&lt;br/&gt;
  * Possible regions:&lt;br/&gt;
  * - points[2]&lt;br/&gt;
  * - edge points[0]-points[2]&lt;br/&gt;
  * - edge points[1]-points[2]&lt;br/&gt;
  * - inside the triangle
  */
 void solve3() {
   vec2 w1 = v1.w;
   vec2 w2 = v2.w;
   vec2 w3 = v3.w;

   // Edge12
   e12.copyFrom(w2).sub(w1);
   num w1e12 = dot(w1, e12);
   num w2e12 = dot(w2, e12);
   num d12_1 = w2e12;
   num d12_2 = -w1e12;

   // Edge13
   e13.copyFrom(w3).sub(w1);
   num w1e13 = dot(w1, e13);
   num w3e13 = dot(w3, e13);
   num d13_1 = w3e13;
   num d13_2 = -w1e13;

   // Edge23
   e23.copyFrom(w3).sub(w2);
   num w2e23 = dot(w2, e23);
   num w3e23 = dot(w3, e23);
   num d23_1 = w3e23;
   num d23_2 = -w2e23;

   // Triangle123
   num n123 = cross(e12, e13);

   num d123_1 = n123 * cross(w2, w3);
   num d123_2 = n123 * cross(w3, w1);
   num d123_3 = n123 * cross(w1, w2);

   // w1 region
   if (d12_2 &lt;= 0.0 &amp;&amp; d13_2 &lt;= 0.0) {
     v1.a = 1.0;
     count = 1;
     return;
   }

   // e12
   if (d12_1 &gt; 0.0 &amp;&amp; d12_2 &gt; 0.0 &amp;&amp; d123_3 &lt;= 0.0) {
     num inv_d12 = 1.0 / (d12_1 + d12_2);
     v1.a = d12_1 * inv_d12;
     v2.a = d12_2 * inv_d12;
     count = 2;
     return;
   }

   // e13
   if (d13_1 &gt; 0.0 &amp;&amp; d13_2 &gt; 0.0 &amp;&amp; d123_2 &lt;= 0.0) {
     num inv_d13 = 1.0 / (d13_1 + d13_2);
     v1.a = d13_1 * inv_d13;
     v3.a = d13_2 * inv_d13;
     count = 2;
     v2.setFrom(v3);
     return;
   }

   // w2 region
   if (d12_1 &lt;= 0.0 &amp;&amp; d23_2 &lt;= 0.0) {
     v2.a = 1.0;
     count = 1;
     v1.setFrom(v2);
     return;
   }

   // w3 region
   if (d13_1 &lt;= 0.0 &amp;&amp; d23_1 &lt;= 0.0) {
     v3.a = 1.0;
     count = 1;
     v1.setFrom(v3);
     return;
   }

   // e23
   if (d23_1 &gt; 0.0 &amp;&amp; d23_2 &gt; 0.0 &amp;&amp; d123_1 &lt;= 0.0) {
     num inv_d23 = 1.0 / (d23_1 + d23_2);
     v2.a = d23_1 * inv_d23;
     v3.a = d23_2 * inv_d23;
     count = 2;
     v1.setFrom(v3);
     return;
   }

   // Must be in triangle123
   num inv_d123 = 1.0 / (d123_1 + d123_2 + d123_3);
   v1.a = d123_1 * inv_d123;
   v2.a = d123_2 * inv_d123;
   v3.a = d123_3 * inv_d123;
   count = 3;
 }
}
</pre>
</div>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="Simplex">
<button class="show-code">Code</button>
new <strong>Simplex</strong>() <a class="anchor-link" href="#Simplex"
              title="Permalink to Simplex.Simplex">#</a></h4>
<div class="doc">
<pre class="source">
Simplex() :
 count = 0,
 v1 = new SimplexVertex(),
 v2 = new SimplexVertex(),
 v3 = new SimplexVertex(),
 vertices = new List&lt;SimplexVertex&gt;(3),
 e13 = new vec2.zero(),
 e12 = new vec2.zero(),
 e23 = new vec2.zero(),
 case2 = new vec2.zero(),
 case22 = new vec2.zero(),
 case3 = new vec2.zero(),
 case33 = new vec2.zero() {

 vertices[0] = v1;
 vertices[1] = v2;
 vertices[2] = v3;
}
</pre>
</div>
</div>
</div>
<div>
<h3>Properties</h3>
<div class="field"><h4 id="case2">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>case2</strong> <a class="anchor-link"
            href="#case2"
            title="Permalink to Simplex.case2">#</a>
        </h4>
        <div class="doc">
<pre class="source">
case2
</pre>
</div>
</div>
<div class="field"><h4 id="case22">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>case22</strong> <a class="anchor-link"
            href="#case22"
            title="Permalink to Simplex.case22">#</a>
        </h4>
        <div class="doc">
<pre class="source">
case22
</pre>
</div>
</div>
<div class="field"><h4 id="case3">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>case3</strong> <a class="anchor-link"
            href="#case3"
            title="Permalink to Simplex.case3">#</a>
        </h4>
        <div class="doc">
<pre class="source">
case3
</pre>
</div>
</div>
<div class="field"><h4 id="case33">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>case33</strong> <a class="anchor-link"
            href="#case33"
            title="Permalink to Simplex.case33">#</a>
        </h4>
        <div class="doc">
<pre class="source">
case33
</pre>
</div>
</div>
<div class="field"><h4 id="count">
<button class="show-code">Code</button>
int         <strong>count</strong> <a class="anchor-link"
            href="#count"
            title="Permalink to Simplex.count">#</a>
        </h4>
        <div class="doc">
<pre class="source">
count
</pre>
</div>
</div>
<div class="field"><h4 id="e12">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>e12</strong> <a class="anchor-link"
            href="#e12"
            title="Permalink to Simplex.e12">#</a>
        </h4>
        <div class="doc">
<pre class="source">
e12
</pre>
</div>
</div>
<div class="field"><h4 id="e13">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>e13</strong> <a class="anchor-link"
            href="#e13"
            title="Permalink to Simplex.e13">#</a>
        </h4>
        <div class="doc">
<pre class="source">
e13
</pre>
</div>
</div>
<div class="field"><h4 id="e23">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>e23</strong> <a class="anchor-link"
            href="#e23"
            title="Permalink to Simplex.e23">#</a>
        </h4>
        <div class="doc">
<pre class="source">
e23
</pre>
</div>
</div>
<div class="field"><h4 id="v1">
<button class="show-code">Code</button>
final <a href="../box2d/SimplexVertex.html">SimplexVertex</a>         <strong>v1</strong> <a class="anchor-link"
            href="#v1"
            title="Permalink to Simplex.v1">#</a>
        </h4>
        <div class="doc">
<pre class="source">
v1
</pre>
</div>
</div>
<div class="field"><h4 id="v2">
<button class="show-code">Code</button>
final <a href="../box2d/SimplexVertex.html">SimplexVertex</a>         <strong>v2</strong> <a class="anchor-link"
            href="#v2"
            title="Permalink to Simplex.v2">#</a>
        </h4>
        <div class="doc">
<pre class="source">
v2
</pre>
</div>
</div>
<div class="field"><h4 id="v3">
<button class="show-code">Code</button>
final <a href="../box2d/SimplexVertex.html">SimplexVertex</a>         <strong>v3</strong> <a class="anchor-link"
            href="#v3"
            title="Permalink to Simplex.v3">#</a>
        </h4>
        <div class="doc">
<pre class="source">
v3
</pre>
</div>
</div>
<div class="field"><h4 id="vertices">
<button class="show-code">Code</button>
final List&lt;<a href="../box2d/SimplexVertex.html">SimplexVertex</a>&gt;         <strong>vertices</strong> <a class="anchor-link"
            href="#vertices"
            title="Permalink to Simplex.vertices">#</a>
        </h4>
        <div class="doc">
<pre class="source">
vertices
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method"><h4 id="getClosestPoint">
<button class="show-code">Code</button>
void <strong>getClosestPoint</strong>(<a href="../vector_math/vec2.html">vec2</a> out) <a class="anchor-link" href="#getClosestPoint"
              title="Permalink to Simplex.getClosestPoint">#</a></h4>
<div class="doc">
<p>this returns pooled objects. don't keep or modify them</p>
<pre class="source">
void getClosestPoint(vec2 out) {
 switch (count) {
   case 0 :
     assert (false);
     out.splat(0.0);
     return;
   case 1 :
     out.copyFrom(v1.w);
     return;
   case 2 :
     case22.copyFrom(v2.w).scale(v2.a);
     case2.copyFrom(v1.w).scale(v1.a).add(case22);
     out.copyFrom(case2);
     return;
   case 3 :
     out.splat(0.0);
     return;
   default :
     assert (false);
     out.splat(0.0);
     return;
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="getMetric">
<button class="show-code">Code</button>
num <strong>getMetric</strong>() <a class="anchor-link" href="#getMetric"
              title="Permalink to Simplex.getMetric">#</a></h4>
<div class="doc">
<pre class="source">
num getMetric() {
 switch (count) {
   case 0 :
     assert (false);
     return 0.0;

   case 1 :
     return 0.0;

   case 2 :
     return distance(v1.w, v2.w);

   case 3 :
     case3.copyFrom(v2.w).sub(v1.w);
     case33.copyFrom(v3.w).sub(v1.w);
     return cross(case3, case33);

   default :
     assert (false);
     return 0.0;
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="getSearchDirection">
<button class="show-code">Code</button>
void <strong>getSearchDirection</strong>(<a href="../vector_math/vec2.html">vec2</a> out) <a class="anchor-link" href="#getSearchDirection"
              title="Permalink to Simplex.getSearchDirection">#</a></h4>
<div class="doc">
<pre class="source">
void getSearchDirection(vec2 out) {
 switch (count) {
   case 1 :
     out.copyFrom(v1.w).negate();
     return;
   case 2 :
     e12.copyFrom(v2.w).sub(v1.w);
     // use out for a temp variable real quick
     out.copyFrom(v1.w).negate();
     num sgn = cross(e12, out);

     if (sgn &gt; 0) {
       // Origin is left of e12.
       out = cross(1, e12);
     }
     else {
       // Origin is right of e12.
       out = cross(e12, 1);
     }
     break;
   default :
     assert (false);
     out.splat(0.0);
     return;
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="getWitnessPoints">
<button class="show-code">Code</button>
void <strong>getWitnessPoints</strong>(<a href="../vector_math/vec2.html">vec2</a> pA, <a href="../vector_math/vec2.html">vec2</a> pB) <a class="anchor-link" href="#getWitnessPoints"
              title="Permalink to Simplex.getWitnessPoints">#</a></h4>
<div class="doc">
<pre class="source">
void getWitnessPoints(vec2 pA, vec2 pB) {
 switch (count) {
   case 0 :
     assert (false);
     break;

   case 1 :
     pA.copyFrom(v1.wA);
     pB.copyFrom(v1.wB);
     break;

   case 2 :
     case2.copyFrom(v1.wA).scale(v1.a);
     pA.copyFrom(v2.wA).scale(v2.a).add(case2);
     case2.copyFrom(v1.wB).scale(v1.a);
     pB.copyFrom(v2.wB).scale(v2.a).add(case2);

     break;

   case 3 :
     pA.copyFrom(v1.wA).scale(v1.a);
     case3.copyFrom(v2.wA).scale(v2.a);
     case33.copyFrom(v3.wA).scale(v3.a);
     pA.add(case3).add(case33);
     pB.copyFrom(pA);
     break;

   default :
     assert (false);
     break;
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="readCache">
<button class="show-code">Code</button>
void <strong>readCache</strong>(<a href="../box2d/SimplexCache.html">SimplexCache</a> cache, <a href="../box2d/DistanceProxy.html">DistanceProxy</a> proxyA, <a href="../box2d/Transform.html">Transform</a> transformA, <a href="../box2d/DistanceProxy.html">DistanceProxy</a> proxyB, <a href="../box2d/Transform.html">Transform</a> transformB) <a class="anchor-link" href="#readCache"
              title="Permalink to Simplex.readCache">#</a></h4>
<div class="doc">
<pre class="source">
void readCache(SimplexCache cache, DistanceProxy proxyA,
   Transform transformA, DistanceProxy proxyB,
   Transform transformB) {
 assert (cache.count &lt;= 3);

 // Copy data from cache.
 count = cache.count;

 for (int i = 0; i &lt; count; ++i) {
   SimplexVertex v = vertices[i];
   v.indexA = cache.indexA[i];
   v.indexB = cache.indexB[i];
   vec2 wALocal = proxyA.vertices[v.indexA];
   vec2 wBLocal = proxyB.vertices[v.indexB];
   Transform.mulToOut(transformA, wALocal, v.wA);
   Transform.mulToOut(transformB, wBLocal, v.wB);
   v.w.copyFrom(v.wB).sub(v.wA);
   v.a = 0.0;
 }

 // Compute the new simplex metric, if it is substantially different than
 // old metric then flush the simplex.
 if (count &gt; 1) {
   num metric1 = cache.metric;
   num metric2 = getMetric();
   if (metric2 &lt; 0.5 * metric1 || 2.0 * metric1 &lt; metric2 || metric2 &lt;
       Settings.EPSILON) {
     // Reset the simplex.
     count = 0;
   }
 }

 // If the cache is empty or invalid ...
 if (count == 0) {
   SimplexVertex v = vertices[0];
   v.indexA = 0;
   v.indexB = 0;
   vec2 wALocal = proxyA.vertices[0];
   vec2 wBLocal = proxyB.vertices[0];
   Transform.mulToOut(transformA, wALocal, v.wA);
   Transform.mulToOut(transformB, wBLocal, v.wB);
   v.w.copyFrom(v.wB).sub(v.wA);
   count = 1;
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="solve2">
<button class="show-code">Code</button>
void <strong>solve2</strong>() <a class="anchor-link" href="#solve2"
              title="Permalink to Simplex.solve2">#</a></h4>
<div class="doc">
<p>Solve a line segment using barycentric coordinates.</p>
<pre class="source">
void solve2() {
 vec2 w1 = v1.w;
 vec2 w2 = v2.w;
 e12.copyFrom(w2).sub(w1);

 // w1 region
 num d12_2 = -dot(w1, e12);
 if (d12_2 &lt;= 0.0) {
   // a2 &lt;= 0, so we clamp it to 0
   v1.a = 1.0;
   count = 1;
   return;
 }

 // w2 region
 num d12_1 = dot(w2, e12);
 if (d12_1 &lt;= 0.0) {
   // a1 &lt;= 0, so we clamp it to 0
   v2.a = 1.0;
   count = 1;
   v1.setFrom(v2);
   return;
 }

 // Must be in e12 region.
 num inv_d12 = 1.0 / (d12_1 + d12_2);
 v1.a = d12_1 * inv_d12;
 v2.a = d12_2 * inv_d12;
 count = 2;
}
</pre>
</div>
</div>
<div class="method"><h4 id="solve3">
<button class="show-code">Code</button>
void <strong>solve3</strong>() <a class="anchor-link" href="#solve3"
              title="Permalink to Simplex.solve3">#</a></h4>
<div class="doc">
<p>Solve a line segment using barycentric coordinates.&lt;br/>
Possible regions:&lt;br/>
- points<code>2</code>&lt;br/>
- edge points<code>0</code>-points<code>2</code>&lt;br/>
- edge points<code>1</code>-points<code>2</code>&lt;br/>
- inside the triangle</p>
<pre class="source">
void solve3() {
 vec2 w1 = v1.w;
 vec2 w2 = v2.w;
 vec2 w3 = v3.w;

 // Edge12
 e12.copyFrom(w2).sub(w1);
 num w1e12 = dot(w1, e12);
 num w2e12 = dot(w2, e12);
 num d12_1 = w2e12;
 num d12_2 = -w1e12;

 // Edge13
 e13.copyFrom(w3).sub(w1);
 num w1e13 = dot(w1, e13);
 num w3e13 = dot(w3, e13);
 num d13_1 = w3e13;
 num d13_2 = -w1e13;

 // Edge23
 e23.copyFrom(w3).sub(w2);
 num w2e23 = dot(w2, e23);
 num w3e23 = dot(w3, e23);
 num d23_1 = w3e23;
 num d23_2 = -w2e23;

 // Triangle123
 num n123 = cross(e12, e13);

 num d123_1 = n123 * cross(w2, w3);
 num d123_2 = n123 * cross(w3, w1);
 num d123_3 = n123 * cross(w1, w2);

 // w1 region
 if (d12_2 &lt;= 0.0 &amp;&amp; d13_2 &lt;= 0.0) {
   v1.a = 1.0;
   count = 1;
   return;
 }

 // e12
 if (d12_1 &gt; 0.0 &amp;&amp; d12_2 &gt; 0.0 &amp;&amp; d123_3 &lt;= 0.0) {
   num inv_d12 = 1.0 / (d12_1 + d12_2);
   v1.a = d12_1 * inv_d12;
   v2.a = d12_2 * inv_d12;
   count = 2;
   return;
 }

 // e13
 if (d13_1 &gt; 0.0 &amp;&amp; d13_2 &gt; 0.0 &amp;&amp; d123_2 &lt;= 0.0) {
   num inv_d13 = 1.0 / (d13_1 + d13_2);
   v1.a = d13_1 * inv_d13;
   v3.a = d13_2 * inv_d13;
   count = 2;
   v2.setFrom(v3);
   return;
 }

 // w2 region
 if (d12_1 &lt;= 0.0 &amp;&amp; d23_2 &lt;= 0.0) {
   v2.a = 1.0;
   count = 1;
   v1.setFrom(v2);
   return;
 }

 // w3 region
 if (d13_1 &lt;= 0.0 &amp;&amp; d23_1 &lt;= 0.0) {
   v3.a = 1.0;
   count = 1;
   v1.setFrom(v3);
   return;
 }

 // e23
 if (d23_1 &gt; 0.0 &amp;&amp; d23_2 &gt; 0.0 &amp;&amp; d123_1 &lt;= 0.0) {
   num inv_d23 = 1.0 / (d23_1 + d23_2);
   v2.a = d23_1 * inv_d23;
   v3.a = d23_2 * inv_d23;
   count = 2;
   v1.setFrom(v3);
   return;
 }

 // Must be in triangle123
 num inv_d123 = 1.0 / (d123_1 + d123_2 + d123_3);
 v1.a = d123_1 * inv_d123;
 v2.a = d123_2 * inv_d123;
 v3.a = d123_3 * inv_d123;
 count = 3;
}
</pre>
</div>
</div>
<div class="method"><h4 id="writeCache">
<button class="show-code">Code</button>
void <strong>writeCache</strong>(<a href="../box2d/SimplexCache.html">SimplexCache</a> cache) <a class="anchor-link" href="#writeCache"
              title="Permalink to Simplex.writeCache">#</a></h4>
<div class="doc">
<pre class="source">
void writeCache(SimplexCache cache) {
 cache.metric = getMetric();
 cache.count = count;

 for (int i = 0; i &lt; count; ++i) {
   cache.indexA[i] = (vertices[i].indexA);
   cache.indexB[i] = (vertices[i].indexB);
 }
}
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
